using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace RecursiveCount
{
    public partial class Main : Form
    {
        int CountTotal = 0;
        System.Int64 SizeTotal = 0;
        string BasePath = "";
        string Pattern = "";
        string Error = "";

        public Main()
        {
            InitializeComponent();
        }

        private void CountFiles(string SearchPath)
        {
            FileInfo FileProperties;
            try
            {
                // Get a list of files in the specified path
                string[] FileList = Directory.GetFiles(SearchPath, Pattern);

                // Get a list of the directories in the specified path
                string[] DirList = Directory.GetDirectories(SearchPath);

                // Add the number of files and size to the running total        
                CountTotal += FileList.Length;
                foreach (string FilePath in FileList)
                {
                    FileProperties = new FileInfo(FilePath);
                    SizeTotal += (FileProperties.Length / 1024);
                }

                ctlOutputNumber.Text = CountTotal.ToString();
                ctlOutputNumber.Refresh();
                ctlOutputSize.Text = SizeTotal.ToString() + " KB";
                ctlOutputSize.Refresh();


                // Loop
                foreach (string DirPath in DirList)
                {
                    CountFiles(DirPath);
                }
            }
            catch (Exception Exc)
            {
                Error = Exc.Message;
            }
        }

        private void ctlRun_Click(object sender, EventArgs e)
        {
            BasePath = ctlInputPath.Text;
            Pattern = ctlInputPattern.Text;
            CountFiles(BasePath);
            CountTotal = 0;
            SizeTotal = 0;
        }

        private void lbl2_Click(object sender, EventArgs e)
        {

        }
    }
}